package pattern.observer.jdk;

import java.util.Observable;

/**
 * JDK提供的一种观察者模式的实现方式，被观察者（继承Observable）
 * @author juxiaojun
 * @since 2019-05-09
 */
public class Learner extends Observable {
    private String name="学习爱好圈";
    private static Learner learner=null;

    private Learner(){}

    public static Learner getInstance(){
        if(null==learner){
            learner=new Learner();
        }
        return learner;
    }

    public String getName() {
        return name;
    }
    public void publishQuestion(Question question){
        System.out.println(question.getUserName() + "在" + this.name + "上提交了一个问题。");
        setChanged();
        notifyObservers(question);
    }
}
